﻿using Newtonsoft.Json;

namespace AEM.Utils
{
    /// <summary>
    /// JSON数据的处理
    /// </summary>
    public class Json
    {
        /// <summary>
        /// 序列化一个对象
        /// </summary>
        /// <param name="obj">要序列化的对象</param>
        /// <returns></returns>
        public static string serialize(object obj)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
        }

        /// <summary>
        /// 反序列化一个对象
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="input">json字符串</param>
        /// <returns></returns>
        public static T deserialize<T>(string input)
        {
            return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(input,
                         new JsonSerializerSettings
                         {
                             TypeNameHandling = TypeNameHandling.All,
                             //TypeNameAssemblyFormat= FormatterAssemblyStyle.Simple,
                         }
                     );
        }
    }
}
